﻿@using MvcForum.Core.Constants
@using MvcForum.Web.Application.ExtensionMethods
@model MvcForum.Web.ViewModels.Admin.BannedWordListViewModel
@{
    ViewBag.Title = "Banned & Stop Words";
}

<div class="panel">
    <div class="panel-heading">
        <h5>@ViewBag.Title</h5>
    </div>
    <div class="panel-content">
        <div class="row">
            <div class="col-md-5">
                @using (Html.BeginForm("Index", "BannedWord", FormMethod.Get))
                {
                    <div class="input-group tablesearch">
                        @Html.TextBoxFor(x => Model.Search, new { @class = "form-control" })
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="submit">Search</button>
                        </span>
                    </div>
                    @Html.Hidden("p", Model.PageIndex)
                }
            </div>
            <div class="col-md-7">
                @using (Html.BeginForm("Add", "BannedWord", FormMethod.Post, new { @class = "form-inline" }))
                {
                    <div class="form-group">
                        <label class="sr-only" for="Word">Word</label>
                        @Html.TextBox("Word", null, new { @class = "form-control" })
                    </div>
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" name="IsStopWord" id="IsStopWord" value="true"> Is Stop Word?
                            <input type="hidden" value="false" name="IsStopWord" />
                        </label>
                    </div>
                    <button type="submit" class="btn btn-default">Add</button>
                }
            </div>
        </div>

        @if (Model.TotalCount > 0)
        {
            <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th style="width: 65px;">Edit</th>
                        <th>Word</th>
                        <th style="width: 120px;">Is Stop Word</th>
                        <th style="width: 65px;">Delete</th>
                    </tr>
                </thead>
                <tbody>

                    @foreach (var word in Model.Words)
                    {
                        <tr>
                            <td>
                                <span class="editbannedword">
                                    <a href="#" class="btn-mvc">
                                        <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                                    </a>
                                </span>
                                <span class="savebannedword" style="display: none;">
                                    <a href="#" class="btn-mvc">
                                        <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
                                    </a>
                                </span>
                            </td>
                            <td class="bannedwordvalue">
                                <span class="bannedwordvaluedisplay">
                                    @Html.Raw(word.Word)
                                </span>
                                <span class="bannedwordvalueedit" style="display: none;">
                                    <input data-wordid="@word.Id" data-oldvalue="@word.Word" type="text" id="@word.Id" value="@word.Word" class="bannedwordinput form-control" />
                                </span>
                            </td>
                            <td>
                                <input type="checkbox" @(word.IsStopWord == true ? "checked=\"checked\"" : "") disabled="disabled" />
                            </td>
                            <td>
                                <a href="@Url.Action("Delete", new { word.Id, p = Model.PageIndex, search = Model.Search })" class="btn-mvc">
                                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
                                </a>
                            </td>
                        </tr>
                    }

                </tbody>
            </table>

            if (Model.Words.TotalPages > 1)
            {
                @Html.Pager(Convert.ToInt32(Model.PageIndex), ForumConfiguration.Instance.AdminListPageSize, Convert.ToInt32(Model.TotalCount), new { search = Model.Search })
            }
        }



    </div>
</div>

<div class="panel">
    <div class="panel-heading">
        <h5>Description</h5>
    </div>
    <div class="panel-content">
        <p><strong>Banned words!</strong> Are words that are matched and are replaced with a charactor that you can define in a web.config app setting called BannedWordReplaceCharactor</p>
        <p>By default its set to '?' (i.e. if you had <strong>feck</strong> in the list, it would become <strong>????</strong>). You can add a single word, or you can add wildcards at the end of your word.</p>
        <p>For example, if you wanted to ban feck, fecking, feckers etc... You can add <strong>feck*</strong> which will match feck AND anything after.</p>
        <p><strong>Stop Words!</strong> If you select a word to be a stop word. Then instead of replacing charactors is just abandons the current action. So for example you could put a stop word as sex.com which would stop link spammers.</p>
        <p>Or you could just use normal words like Viagra, which would stop anyone trying to post with that in (This also applies to profiles, so they can't sign up just to get a link).</p>
    </div>
</div>